<template>
  <div class="hospitalsign">
    <div class="top">
      <div class="title">医院选择</div>
      <div class="topinfo">
        <van-radio-group v-model="tjyy" v-for="(item, i) in list" :key="i">
          <van-radio :name="item.val">{{ item.name }}</van-radio>
        </van-radio-group>
      </div>
    </div>
    <div class="sign-btn" @click="submit">报名</div>
  </div>
</template>

<script>
import {tjryQuerydata4list, tjrySaveDjzxxDataOrUpdate} from '@/assets/js/api';

export default {
  data() {
    return {
      tjyy: '',
      tjjhId: this.$route.query.id,
      dspToken: localStorage.dspToken,
      list: []
    };
  },
  mounted() {
    tjryQuerydata4list({
      dspToken: this.dspToken,
      tjjhId: this.tjjhId
    }).then(({data}) => {
      this.list = data.filter(o => o.name);
    });
  },
  methods: {
    submit() {
      if (this.tjyy) {
        tjrySaveDjzxxDataOrUpdate({
          tjjhId: this.tjjhId,
          tjyy: this.tjyy,
          dspToken: this.dspToken
        }).then(({pkValue}) => {
          if (pkValue === '已报过名') {
            this.$toast('已报过名，请勿重复提交');
          } else {
            this.$toast('报名成功！');
            history.go(-1);
          }
        });
      } else {
        this.$toast('请选择医院');
        return false;
      }
    }
  }
};
</script>

<style lang="less" scoped>
.hospitalsign {
  padding: 24px;
  .top {
    width: 704px;
    background-color: #ffffff;
    box-shadow: 3px 4px 9px 1px rgba(1, 88, 155, 0.05);
    border-radius: 8px;
    margin: 0 auto;
    .title {
      height: 64px;
      background-color: #3198ed;
      color: #ffffff;
      font-size: 30px;
      line-height: 64px;
      padding: 0 16px;
      border-top-left-radius: 8px;
      border-top-right-radius: 8px;
    }
    .topinfo {
      padding: 0 18px;
      box-sizing: border-box;
      width: 674px;
      margin: 0 auto;
      font-size: 34px;
      color: #343434;
      /deep/ .van-radio-group {
        line-height: 3;
        &:not(:last-child) {
          border-bottom: 1px solid #eeeeee;
        }
        .van-radio {
          &:not(:last-child) {
            padding-right: 20px;
          }
          .van-radio__icon {
            font-size: inherit;
          }
          .van-radio__label {
            height: auto;
            line-height: inherit;
          }
        }
      }
    }
  }
  .sign-btn {
    border: none;
    width: 704px;
    height: 90px;
    background-color: #3198ed;
    box-shadow: 0px 5px 5px 0px rgba(89, 166, 250, 0.1);
    border-radius: 45px;
    line-height: 90px;
    color: #ffffff;
    font-size: 36px;
    text-align: center;
    margin: 26px auto;
    letter-spacing: 7px;
  }
}
</style>
